@ai-matrx/sharing 0.1.1 → 0.1.3

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/dist/core.cjs CHANGED
@@ -459,7 +459,7 @@ var SHAREABLE_RESOURCE_REGISTRY = {
459
459
  context_item: {
460
460
  // Mirrors the live platform.shareable_resource_registry row, which still names the retired
461
461
  // context.context_items: a context field lives in the record store now, and
462
- // public.resolve_shareable_resource REFUSES this token BY NAME ("share the record itself") —
462
+ // iam.resolve_shareable_resource REFUSES this token BY NAME ("share the record itself") —
463
463
  // the same decision the generic registry readers take (platform.record_store_kind,
464
464
  // SCOPES-CLEANUP 2026-10-09). Not a table any share path may read.
465
465
  resourceType: "context_item",
@@ -899,7 +899,7 @@ var SHAREABLE_RESOURCE_REGISTRY = {
899
899
  // TS↔DB guard stays green.
900
900
  scope: {
901
901
  // Mirrors the live registry row (the retired context.scopes). A scope is a record-store Record:
902
- // public.resolve_shareable_resource REFUSES this token BY NAME, as for context_item above.
902
+ // iam.resolve_shareable_resource REFUSES this token BY NAME, as for context_item above.
903
903
  resourceType: "scope",
904
904
  tableName: "scopes",
905
905
  schemaName: "context",
@@ -3696,13 +3696,16 @@ async function getShareCapabilities(resourceType) {
3696
3696
  rowChildColumn: typeof data.row_child_column === "string" ? data.row_child_column : null
3697
3697
  };
3698
3698
  }
3699
- function shareLinkUrl(token) {
3700
- const base = process.env.NEXT_PUBLIC_APP_URL || (typeof window !== "undefined" ? window.location.origin : "");
3701
- return `${base}/s/${token}`;
3699
+ function shareBase(origin) {
3700
+ const base = origin || process.env.NEXT_PUBLIC_APP_URL || (typeof window !== "undefined" ? window.location.origin : "");
3701
+ return base.replace(/\/+$/, "");
3702
3702
  }
3703
- function shareUrlForLink(link) {
3704
- const base = process.env.NEXT_PUBLIC_APP_URL || (typeof window !== "undefined" ? window.location.origin : "");
3705
- return link.shortToken ? (0, import_short_link.shortLinkUrl)(base, link.shortToken) : shareLinkUrl(link.token);
3703
+ function shareLinkUrl(token, origin) {
3704
+ return `${shareBase(origin)}/s/${token}`;
3705
+ }
3706
+ function shareUrlForLink(link, origin) {
3707
+ const base = shareBase(origin);
3708
+ return link.shortToken ? (0, import_short_link.shortLinkUrl)(base, link.shortToken) : shareLinkUrl(link.token, base);
3706
3709
  }
3707
3710
  async function createShareLink(options) {
3708
3711
  try {
@@ -3773,7 +3776,7 @@ async function forkSharedResource(resourceType, resourceId, shareToken, organiza
3773
3776
  try {
3774
3777
  const orgId = await ensureOrgId(organizationId);
3775
3778
  if (resourceType === "conversation") {
3776
- const { data, error } = await supabase.rpc("fork_shared_conversation", {
3779
+ const { data, error } = await supabase.schema("chat").rpc("fork_shared_conversation", {
3777
3780
  p_conversation_id: resourceId,
3778
3781
  p_organization_id: orgId,
3779
3782
  p_token: shareToken ?? void 0
@@ -3783,7 +3786,7 @@ async function forkSharedResource(resourceType, resourceId, shareToken, organiza
3783
3786
  return r?.success ? { success: true, path: `/chat/${r.conversation_id}` } : { success: false, error: r?.error };
3784
3787
  }
3785
3788
  if (resourceType === "fc_set") {
3786
- const { data, error } = await supabase.rpc("fork_shared_flashcard_set", {
3789
+ const { data, error } = await supabase.schema("education").rpc("fork_shared_flashcard_set", {
3787
3790
  p_set_id: resourceId,
3788
3791
  p_organization_id: orgId,
3789
3792
  p_token: shareToken ?? void 0
@@ -3793,7 +3796,7 @@ async function forkSharedResource(resourceType, resourceId, shareToken, organiza
3793
3796
  return r?.success ? { success: true, path: `/education/flashcards/${r.set_id}` } : { success: false, error: r?.error };
3794
3797
  }
3795
3798
  if (resourceType === "quiz_session") {
3796
- const { data, error } = await supabase.rpc("fork_shared_quiz", {
3799
+ const { data, error } = await supabase.schema("education").rpc("fork_shared_quiz", {
3797
3800
  p_quiz_id: resourceId,
3798
3801
  p_organization_id: orgId,
3799
3802
  p_token: shareToken ?? void 0
@@ -3814,7 +3817,7 @@ function isForkable(resourceType) {
3814
3817
  return resourceType === "conversation" || resourceType === "fc_set" || resourceType === "quiz_session";
3815
3818
  }
3816
3819
  async function resolveShareToken(token, client = supabase) {
3817
- const { data, error } = await client.rpc("resolve_share_token", {
3820
+ const { data, error } = await client.schema("iam").rpc("resolve_share_token", {
3818
3821
  p_token: token
3819
3822
  });
3820
3823
  if (error) {
@@ -3898,7 +3901,7 @@ async function writeRowControl(resourceType, resourceId, patch) {
3898
3901
  return { success: true };
3899
3902
  }
3900
3903
  async function writeStoreRowControls(resourceType, resourceId, controls) {
3901
- const { data: lane, error: laneError } = await supabase.rpc("store_door_lane", {
3904
+ const { data: lane, error: laneError } = await supabase.schema("workbench").rpc("store_door_lane", {
3902
3905
  p_resource_type: resourceType,
3903
3906
  p_resource_id: resourceId
3904
3907
  });
@@ -3932,7 +3935,7 @@ async function getResourceVisibility(resourceType, resourceId) {
3932
3935
  );
3933
3936
  }
3934
3937
  if (entry.schemaName === "custom") {
3935
- const { data: data2, error: error2 } = await supabase.rpc("store_door_lane", {
3938
+ const { data: data2, error: error2 } = await supabase.schema("workbench").rpc("store_door_lane", {
3936
3939
  p_resource_type: resourceType,
3937
3940
  p_resource_id: resourceId
3938
3941
  });
@@ -4051,7 +4054,7 @@ async function shareWithUser(options) {
4051
4054
  permissionLevel,
4052
4055
  organizationId
4053
4056
  } = options;
4054
- const { data, error } = await supabase.rpc("share_resource_with_user", {
4057
+ const { data, error } = await supabase.schema("iam").rpc("share_resource_with_user", {
4055
4058
  p_resource_type: resourceType,
4056
4059
  p_resource_id: resourceId,
4057
4060
  p_target_user_id: userId,
@@ -4102,7 +4105,7 @@ async function shareWithUser(options) {
4102
4105
  async function grantOrgAvailability(options) {
4103
4106
  try {
4104
4107
  const { resourceType, resourceId, organizationId, permissionLevel } = options;
4105
- const { data, error } = await supabase.rpc("grant_org_availability", {
4108
+ const { data, error } = await supabase.schema("iam").rpc("grant_org_availability", {
4106
4109
  p_resource_type: resourceType,
4107
4110
  p_resource_id: resourceId,
4108
4111
  p_target_org_id: organizationId,
@@ -4164,7 +4167,7 @@ async function makePrivate(resourceType, resourceId) {
4164
4167
  }
4165
4168
  async function revokeUserAccess(resourceType, resourceId, userId) {
4166
4169
  try {
4167
- const { data, error } = await supabase.rpc("revoke_resource_access", {
4170
+ const { data, error } = await supabase.schema("iam").rpc("revoke_resource_access", {
4168
4171
  p_resource_type: resourceType,
4169
4172
  p_resource_id: resourceId,
4170
4173
  p_target_user_id: userId
@@ -4187,7 +4190,7 @@ async function revokeUserAccess(resourceType, resourceId, userId) {
4187
4190
  }
4188
4191
  async function revokeOrgAccess(resourceType, resourceId, organizationId) {
4189
4192
  try {
4190
- const { data, error } = await supabase.rpc("revoke_resource_org_access", {
4193
+ const { data, error } = await supabase.schema("iam").rpc("revoke_resource_org_access", {
4191
4194
  p_resource_type: resourceType,
4192
4195
  p_resource_id: resourceId,
4193
4196
  p_target_org_id: organizationId
@@ -4228,7 +4231,7 @@ async function updatePermissionLevel(options) {
4228
4231
  if (!userId && !organizationId) {
4229
4232
  return { success: false, error: "Must specify userId or organizationId" };
4230
4233
  }
4231
- const { data, error } = await supabase.rpc("update_permission_level", {
4234
+ const { data, error } = await supabase.schema("iam").rpc("update_permission_level", {
4232
4235
  p_resource_type: resourceType,
4233
4236
  p_resource_id: resourceId,
4234
4237
  p_target_user_id: userId,
@@ -4256,7 +4259,7 @@ async function updatePermissionLevel(options) {
4256
4259
  }
4257
4260
  async function listPermissions(resourceType, resourceId) {
4258
4261
  try {
4259
- const { data, error } = await supabase.rpc("get_resource_permissions", {
4262
+ const { data, error } = await supabase.schema("iam").rpc("get_resource_permissions", {
4260
4263
  p_resource_type: resourceType,
4261
4264
  p_resource_id: resourceId
4262
4265
  });
@@ -4335,7 +4338,7 @@ async function resolveSharingAuthority(resourceType, resourceId) {
4335
4338
  };
4336
4339
  }
4337
4340
  try {
4338
- const { data, error } = await supabase.rpc("may_manage_sharing", {
4341
+ const { data, error } = await supabase.schema("iam").rpc("may_manage_sharing", {
4339
4342
  p_resource_type: resourceType,
4340
4343
  p_resource_id: resourceId
4341
4344
  });
@@ -4630,7 +4633,7 @@ async function fetchEntityTitles(entityType, ids) {
4630
4633
  const unique = Array.from(new Set(ids.filter(Boolean)));
4631
4634
  if (unique.length === 0) return out;
4632
4635
  const supabase2 = createClient();
4633
- const { data, error } = await supabase2.rpc("entity_titles", {
4636
+ const { data, error } = await supabase2.schema("platform").rpc("entity_titles", {
4634
4637
  p_type: entityType,
4635
4638
  p_ids: unique
4636
4639
  });
@@ -5149,7 +5152,7 @@ async function revokeOutside(organizationId, invitationId) {
5149
5152
  return data;
5150
5153
  }
5151
5154
  async function peekTableShare(token) {
5152
- const { data, error } = await createClient().rpc("table_share_peek", { p_token: token });
5155
+ const { data, error } = await createClient().schema("iam").rpc("table_share_peek", { p_token: token });
5153
5156
  if (error) throw new Error(error.message);
5154
5157
  return data;
5155
5158
  }
@@ -5305,7 +5308,7 @@ function readOrganizationMemberRows2(orgId, {
5305
5308
  const db = client ?? createClient();
5306
5309
  const entry = { at: now, settled: false, rows: Promise.resolve([]) };
5307
5310
  const rows = (async () => {
5308
- const { data, error } = await db.rpc("get_organization_members_with_users", {
5311
+ const { data, error } = await db.schema("iam").rpc("get_organization_members_with_users", {
5309
5312
  p_org_id: orgId
5310
5313
  });
5311
5314
  if (error) throw (0, import_data.pgErrorToError)(error);
@@ -5352,7 +5355,7 @@ function toRole(value) {
5352
5355
  return value === "admin" || value === "member" ? value : null;
5353
5356
  }
5354
5357
  async function listTeams(organizationId, includeArchived = false) {
5355
- const { data, error } = await shareClient().rpc("team_list", { p_organization_id: organizationId, p_include_archived: includeArchived });
5358
+ const { data, error } = await shareClient().schema("iam").rpc("team_list", { p_organization_id: organizationId, p_include_archived: includeArchived });
5356
5359
  if (error) throw (0, import_data2.pgErrorToError)(error);
5357
5360
  return (data ?? []).map((row) => ({
5358
5361
  id: String(row.id),
@@ -5368,7 +5371,7 @@ async function listTeams(organizationId, includeArchived = false) {
5368
5371
  }));
5369
5372
  }
5370
5373
  async function listTeamMembers(teamId) {
5371
- const { data, error } = await shareClient().rpc("team_members", { p_team_id: teamId });
5374
+ const { data, error } = await shareClient().schema("iam").rpc("team_members", { p_team_id: teamId });
5372
5375
  if (error) throw (0, import_data2.pgErrorToError)(error);
5373
5376
  return (data ?? []).map((row) => ({
5374
5377
  userId: String(row.user_id),