@cargo-ai/api 1.0.133 → 1.0.134

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.
@@ -8,6 +8,17 @@ export type OauthApi = {
8
8
  list: (payload: Oauth.Api.ListGrantsPayload) => Promise<Oauth.Api.ListGrantsResult>;
9
9
  revoke: (payload: Oauth.Api.RevokeGrantPayload) => Promise<void>;
10
10
  };
11
+ /**
12
+ * What the calling OAuth app keeps about the current workspace, such as its
13
+ * settings, as keys and JSON values. Only an OAuth app's token reaches it,
14
+ * and only its own keys.
15
+ */
16
+ meta: {
17
+ /** The value under a key, or undefined when the key was never set. */
18
+ get: (key: string) => Promise<unknown>;
19
+ set: (payload: Oauth.Api.SetMetaPayload) => Promise<void>;
20
+ remove: (key: string) => Promise<void>;
21
+ };
11
22
  /** The apps with access to the signed-in user's account. */
12
23
  userGrant: {
13
24
  list: () => Promise<Oauth.Api.ListUserGrantsResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/api/oauth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAGtD,KAAK,oBAAoB,GAAG;IAC1B,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE;QACL,IAAI,EAAE,CACJ,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,iBAAiB,KACjC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QACzC,MAAM,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;KAClE,CAAC;IACF,4DAA4D;IAC5D,SAAS,EAAE;QACT,IAAI,EAAE,MAAM,OAAO,CAAC,KAA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AAC,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,sBAAsB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;KACtE,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,aAAa,gBAAiB,oBAAoB,KAAG,QAmJjE,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { Oauth } from "../../domains/index.js";
2
- import { getErrorWithReasonErrorMessage } from "../../fetcher/index.js";
2
+ import { determineIfIsFetcherError, getErrorWithReasonErrorMessage, } from "../../fetcher/index.js";
3
3
  export const buildOauthApi = ({ fetcher }) => {
4
4
  async function listGrants(payload) {
5
5
  try {
@@ -32,6 +32,56 @@ export const buildOauthApi = ({ fetcher }) => {
32
32
  });
33
33
  }
34
34
  }
35
+ // A value is the app's own data, so a null inside it stays a null.
36
+ async function getMeta(key) {
37
+ try {
38
+ const result = await fetcher.fetch({
39
+ method: "get",
40
+ endpoint: `oauth/meta/${encodeURIComponent(key)}`,
41
+ replaceNullByUndefined: false,
42
+ });
43
+ return result.value;
44
+ }
45
+ catch (error) {
46
+ // A key never set is an answer, not a failure.
47
+ if (determineIfIsFetcherError(error) === true &&
48
+ error.type === "RequestError" &&
49
+ error.reason === "keyNotFound") {
50
+ return undefined;
51
+ }
52
+ throw getErrorWithReasonErrorMessage(error, Oauth.Api.zodGetMetaErrorReason, {
53
+ onlyForOauthApps: "Only an OAuth app keeps meta.",
54
+ keyNotFound: "Key not found.",
55
+ });
56
+ }
57
+ }
58
+ async function setMeta(payload) {
59
+ try {
60
+ await fetcher.fetch({
61
+ method: "put",
62
+ endpoint: `oauth/meta/${encodeURIComponent(payload.key)}`,
63
+ payload: { value: payload.value },
64
+ });
65
+ }
66
+ catch (error) {
67
+ throw getErrorWithReasonErrorMessage(error, Oauth.Api.zodMetaErrorReason, {
68
+ onlyForOauthApps: "Only an OAuth app keeps meta.",
69
+ });
70
+ }
71
+ }
72
+ async function removeMeta(key) {
73
+ try {
74
+ await fetcher.fetch({
75
+ method: "delete",
76
+ endpoint: `oauth/meta/${encodeURIComponent(key)}`,
77
+ });
78
+ }
79
+ catch (error) {
80
+ throw getErrorWithReasonErrorMessage(error, Oauth.Api.zodMetaErrorReason, {
81
+ onlyForOauthApps: "Only an OAuth app keeps meta.",
82
+ });
83
+ }
84
+ }
35
85
  async function listUserGrants() {
36
86
  return await fetcher.fetch({
37
87
  method: "get",
@@ -56,6 +106,11 @@ export const buildOauthApi = ({ fetcher }) => {
56
106
  list: listGrants,
57
107
  revoke: revokeGrant,
58
108
  },
109
+ meta: {
110
+ get: getMeta,
111
+ set: setMeta,
112
+ remove: removeMeta,
113
+ },
59
114
  userGrant: {
60
115
  list: listUserGrants,
61
116
  revoke: revokeUserGrant,
@@ -30,6 +30,22 @@ export declare namespace Oauth {
30
30
  const zodRevokeUserGrantErrorReason: z.ZodEnum<{
31
31
  grantNotFound: "grantNotFound";
32
32
  }>;
33
+ type GetMetaResult = {
34
+ /** The value the calling app stored, exactly as it stored it. */
35
+ value: unknown;
36
+ };
37
+ const zodGetMetaErrorReason: z.ZodEnum<{
38
+ onlyForOauthApps: "onlyForOauthApps";
39
+ keyNotFound: "keyNotFound";
40
+ }>;
41
+ type SetMetaPayload = {
42
+ key: string;
43
+ /** Any JSON but null, at most 64 KB. */
44
+ value: unknown;
45
+ };
46
+ const zodMetaErrorReason: z.ZodEnum<{
47
+ onlyForOauthApps: "onlyForOauthApps";
48
+ }>;
33
49
  }
34
50
  const grantKeys: {
35
51
  list: (workspaceUuid: string, resource: string) => readonly ["oauthGrants", string, string];
@@ -1 +1 @@
1
- {"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../../src/domains/oauth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAG3C,yBAAiB,KAAK,CAAC;IACrB,KAAY,KAA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CAAC;YAClB,QAAQ,EAAE,MAAM,CAAC;SAClB,CAAC;QAEK,MAAM,yBAAyB;;;UAGpC,CAAC;QAEH,KAAY,oBAAoB,GAAG;YACjC,MAAM,EAAE,KAAK,EAAE,CAAC;SACjB,CAAC;QAEF,KAAY,sBAAsB,GAAG;YACnC,SAAS,EAAE,MAAM,CAAC;SACnB,CAAC;QAEK,MAAM,6BAA6B;;UAA4B,CAAC;QAEvE,KAAY,aAAa,GAAG;YAC1B,iEAAiE;YACjE,KAAK,EAAE,OAAO,CAAC;SAChB,CAAC;QAEK,MAAM,qBAAqB;;;UAGhC,CAAC;QAEH,KAAY,cAAc,GAAG;YAC3B,GAAG,EAAE,MAAM,CAAC;YACZ,wCAAwC;YACxC,KAAK,EAAE,OAAO,CAAC;SAChB,CAAC;QAEK,MAAM,kBAAkB;;UAA+B,CAAC;KAChE;IAEM,MAAM,SAAS;8BACE,MAAM,YAAY,MAAM;;KAG/C,CAAC;CACH"}
@@ -11,6 +11,11 @@ export var Oauth;
11
11
  "grantNotFound",
12
12
  ]);
13
13
  Api.zodRevokeUserGrantErrorReason = z.enum(["grantNotFound"]);
14
+ Api.zodGetMetaErrorReason = z.enum([
15
+ "onlyForOauthApps",
16
+ "keyNotFound",
17
+ ]);
18
+ Api.zodMetaErrorReason = z.enum(["onlyForOauthApps"]);
14
19
  })(Api = Oauth.Api || (Oauth.Api = {}));
15
20
  Oauth.grantKeys = {
16
21
  list: (workspaceUuid, resource) => ["oauthGrants", workspaceUuid, resource],