primcli 1.17.0 → 1.18.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.
@@ -22242,6 +22242,31 @@ const operationManifest = [
22242
22242
  }
22243
22243
  ];
22244
22244
  //#endregion
22245
+ //#region ../packages/api-core/src/memories.ts
22246
+ function isPlainJsonObject(value) {
22247
+ const prototype = Object.getPrototypeOf(value);
22248
+ return prototype === Object.prototype || prototype === null;
22249
+ }
22250
+ function isMemoryJsonValue(value, seen = /* @__PURE__ */ new Set()) {
22251
+ if (value === null) return true;
22252
+ if (typeof value === "string" || typeof value === "boolean") return true;
22253
+ if (typeof value === "number") return Number.isFinite(value);
22254
+ if (typeof value !== "object") return false;
22255
+ if (seen.has(value)) return false;
22256
+ seen.add(value);
22257
+ try {
22258
+ if (Array.isArray(value)) {
22259
+ for (let index = 0; index < value.length; index += 1) if (!(index in value) || !isMemoryJsonValue(value[index], seen)) return false;
22260
+ return true;
22261
+ }
22262
+ if (!isPlainJsonObject(value)) return false;
22263
+ for (const nested of Object.values(value)) if (!isMemoryJsonValue(nested, seen)) return false;
22264
+ return true;
22265
+ } finally {
22266
+ seen.delete(value);
22267
+ }
22268
+ }
22269
+ //#endregion
22245
22270
  //#region src/oclif/api-client.ts
22246
22271
  const API_HEADERS_ENV = "PRIMITIVE_API_HEADERS";
22247
22272
  const OAUTH_REFRESH_SKEW_MS = 60 * 1e3;
@@ -26542,8 +26567,8 @@ const PRIMITIVE_TEAM_AUTHOR = {
26542
26567
  name: "Primitive Team",
26543
26568
  url: "https://primitive.dev"
26544
26569
  };
26545
- const SDK_VERSION_RANGE = "^1.17.0";
26546
- const CLI_VERSION_RANGE = "^1.17.0";
26570
+ const SDK_VERSION_RANGE = "^1.18.0";
26571
+ const CLI_VERSION_RANGE = "^1.18.0";
26547
26572
  const ESBUILD_VERSION_RANGE = "^0.27.0";
26548
26573
  function renderHandler() {
26549
26574
  return `// env.PRIMITIVE_API_KEY, env.PRIMITIVE_WEBHOOK_SECRET, and
@@ -29689,6 +29714,7 @@ var LogoutCommand = class LogoutCommand extends Command {
29689
29714
  };
29690
29715
  //#endregion
29691
29716
  //#region src/oclif/commands/memories.ts
29717
+ var MemoryCliInputError = class extends Error {};
29692
29718
  const API_KEY_FLAG = Flags.string({
29693
29719
  description: "Primitive API key override (defaults to PRIMITIVE_API_KEY or saved OAuth login credentials)",
29694
29720
  env: "PRIMITIVE_API_KEY"
@@ -29721,11 +29747,27 @@ function printData(command, responseData) {
29721
29747
  const data = responseData?.data ?? null;
29722
29748
  command.log(JSON.stringify(data, null, 2));
29723
29749
  }
29750
+ function handleMemoryInputError(error) {
29751
+ if (!(error instanceof MemoryCliInputError)) return false;
29752
+ process.stderr.write(`${error.message}\n`);
29753
+ process.exitCode = 1;
29754
+ return true;
29755
+ }
29756
+ function nonEmptyFlag(value, name) {
29757
+ if (value === void 0) return void 0;
29758
+ if (value.trim().length === 0) throw new MemoryCliInputError(`${name} must be a non-empty string.`);
29759
+ return value;
29760
+ }
29724
29761
  function parseMemoryJson(source, label = "value") {
29725
29762
  try {
29763
+ const value = JSON.parse(source);
29764
+ if (!isMemoryJsonValue(value)) return {
29765
+ kind: "error",
29766
+ message: `${label} must be valid JSON. Numbers must be finite, arrays must not be sparse, and values may not contain undefined, bigint, symbol, function, class instance, or cyclic entries.`
29767
+ };
29726
29768
  return {
29727
29769
  kind: "ok",
29728
- value: JSON.parse(source)
29770
+ value
29729
29771
  };
29730
29772
  } catch (error) {
29731
29773
  return {
@@ -29762,31 +29804,63 @@ function resolveMemoryValueSource(input) {
29762
29804
  };
29763
29805
  }
29764
29806
  function memoryScopeForBody(flags) {
29765
- if (flags.function) return {
29807
+ const functionId = nonEmptyFlag(flags.function, "--function");
29808
+ if (functionId !== void 0) return {
29766
29809
  type: "function",
29767
- id: flags.function
29810
+ id: functionId
29768
29811
  };
29769
29812
  if (flags.org) return { type: "org" };
29770
29813
  }
29771
29814
  function memoryScopeForQuery(flags) {
29772
- if (flags.function) return {
29815
+ const functionId = nonEmptyFlag(flags.function, "--function");
29816
+ if (functionId !== void 0) return {
29773
29817
  scope_type: "function",
29774
- scope_id: flags.function
29818
+ scope_id: functionId
29775
29819
  };
29776
29820
  if (flags.org) return { scope_type: "org" };
29777
29821
  return {};
29778
29822
  }
29779
29823
  function buildSetMemoryInput(params) {
29780
29824
  const scope = memoryScopeForBody(params.flags);
29825
+ const expiresAt = nonEmptyFlag(params.flags["expires-at"], "--expires-at");
29826
+ const ifVersion = nonEmptyFlag(params.flags["if-version"], "--if-version");
29781
29827
  return {
29782
29828
  key: params.key,
29783
29829
  value: params.value,
29784
29830
  ...scope ? { scope } : {},
29785
29831
  ...params.flags["ttl-seconds"] !== void 0 ? { ttl_seconds: params.flags["ttl-seconds"] } : {},
29786
- ...params.flags["expires-at"] ? { expires_at: params.flags["expires-at"] } : {},
29832
+ ...expiresAt !== void 0 ? { expires_at: expiresAt } : {},
29787
29833
  ...params.flags["clear-ttl"] ? { clear_ttl: true } : {},
29788
29834
  ...params.flags["if-absent"] ? { if_absent: true } : {},
29789
- ...params.flags["if-version"] ? { if_version: params.flags["if-version"] } : {}
29835
+ ...ifVersion !== void 0 ? { if_version: ifVersion } : {}
29836
+ };
29837
+ }
29838
+ function buildGetMemoryQuery(params) {
29839
+ return {
29840
+ key: params.key,
29841
+ ...memoryScopeForQuery(params.flags)
29842
+ };
29843
+ }
29844
+ function buildDeleteMemoryQuery(params) {
29845
+ const ifVersion = nonEmptyFlag(params.flags["if-version"], "--if-version");
29846
+ return {
29847
+ key: params.key,
29848
+ ...memoryScopeForQuery(params.flags),
29849
+ ...ifVersion !== void 0 ? { if_version: ifVersion } : {}
29850
+ };
29851
+ }
29852
+ function buildSearchMemoriesQuery(params) {
29853
+ const cursor = nonEmptyFlag(params.flags.cursor, "--cursor");
29854
+ const updatedAfter = nonEmptyFlag(params.flags["updated-after"], "--updated-after");
29855
+ const updatedBefore = nonEmptyFlag(params.flags["updated-before"], "--updated-before");
29856
+ return {
29857
+ ...params.prefix !== void 0 ? { prefix: params.prefix } : {},
29858
+ limit: params.flags.limit,
29859
+ ...cursor !== void 0 ? { cursor } : {},
29860
+ ...params.flags["metadata-only"] ? { include_value: "false" } : {},
29861
+ ...updatedAfter !== void 0 ? { updated_after: updatedAfter } : {},
29862
+ ...updatedBefore !== void 0 ? { updated_before: updatedBefore } : {},
29863
+ ...memoryScopeForQuery(params.flags)
29790
29864
  };
29791
29865
  }
29792
29866
  var MemoriesSetCommand = class MemoriesSetCommand extends Command {
@@ -29857,6 +29931,17 @@ var MemoriesSetCommand = class MemoriesSetCommand extends Command {
29857
29931
  process.exitCode = 1;
29858
29932
  return;
29859
29933
  }
29934
+ let body;
29935
+ try {
29936
+ body = buildSetMemoryInput({
29937
+ key: args.key,
29938
+ value: parsed.value,
29939
+ flags
29940
+ });
29941
+ } catch (error) {
29942
+ if (handleMemoryInputError(error)) return;
29943
+ throw error;
29944
+ }
29860
29945
  const { apiClient, auth, baseUrlOverridden } = await createAuthenticatedCliApiClient({
29861
29946
  apiKey: flags["api-key"],
29862
29947
  apiBaseUrl: flags["api-base-url"],
@@ -29865,11 +29950,7 @@ var MemoriesSetCommand = class MemoriesSetCommand extends Command {
29865
29950
  await runWithTiming(flags.time, async () => {
29866
29951
  const result = await setMemory({
29867
29952
  client: apiClient.client,
29868
- body: buildSetMemoryInput({
29869
- key: args.key,
29870
- value: parsed.value,
29871
- flags
29872
- }),
29953
+ body,
29873
29954
  responseStyle: "fields"
29874
29955
  });
29875
29956
  if (result.error) {
@@ -29903,6 +29984,16 @@ var MemoriesGetCommand = class MemoriesGetCommand extends Command {
29903
29984
  };
29904
29985
  async run() {
29905
29986
  const { args, flags } = await this.parse(MemoriesGetCommand);
29987
+ let query;
29988
+ try {
29989
+ query = buildGetMemoryQuery({
29990
+ key: args.key,
29991
+ flags
29992
+ });
29993
+ } catch (error) {
29994
+ if (handleMemoryInputError(error)) return;
29995
+ throw error;
29996
+ }
29906
29997
  const { apiClient, auth, baseUrlOverridden } = await createAuthenticatedCliApiClient({
29907
29998
  apiKey: flags["api-key"],
29908
29999
  apiBaseUrl: flags["api-base-url"],
@@ -29911,10 +30002,7 @@ var MemoriesGetCommand = class MemoriesGetCommand extends Command {
29911
30002
  await runWithTiming(flags.time, async () => {
29912
30003
  const result = await getMemory({
29913
30004
  client: apiClient.client,
29914
- query: {
29915
- key: args.key,
29916
- ...memoryScopeForQuery(flags)
29917
- },
30005
+ query,
29918
30006
  responseStyle: "fields"
29919
30007
  });
29920
30008
  if (result.error) {
@@ -29950,6 +30038,16 @@ var MemoriesDeleteCommand = class MemoriesDeleteCommand extends Command {
29950
30038
  };
29951
30039
  async run() {
29952
30040
  const { args, flags } = await this.parse(MemoriesDeleteCommand);
30041
+ let query;
30042
+ try {
30043
+ query = buildDeleteMemoryQuery({
30044
+ key: args.key,
30045
+ flags
30046
+ });
30047
+ } catch (error) {
30048
+ if (handleMemoryInputError(error)) return;
30049
+ throw error;
30050
+ }
29953
30051
  const { apiClient, auth, baseUrlOverridden } = await createAuthenticatedCliApiClient({
29954
30052
  apiKey: flags["api-key"],
29955
30053
  apiBaseUrl: flags["api-base-url"],
@@ -29958,11 +30056,7 @@ var MemoriesDeleteCommand = class MemoriesDeleteCommand extends Command {
29958
30056
  await runWithTiming(flags.time, async () => {
29959
30057
  const result = await deleteMemory({
29960
30058
  client: apiClient.client,
29961
- query: {
29962
- key: args.key,
29963
- ...memoryScopeForQuery(flags),
29964
- ...flags["if-version"] ? { if_version: flags["if-version"] } : {}
29965
- },
30059
+ query,
29966
30060
  responseStyle: "fields"
29967
30061
  });
29968
30062
  if (result.error) {
@@ -30007,6 +30101,16 @@ var MemoriesSearchCommand = class MemoriesSearchCommand extends Command {
30007
30101
  };
30008
30102
  async run() {
30009
30103
  const { args, flags } = await this.parse(MemoriesSearchCommand);
30104
+ let query;
30105
+ try {
30106
+ query = buildSearchMemoriesQuery({
30107
+ prefix: args.prefix,
30108
+ flags
30109
+ });
30110
+ } catch (error) {
30111
+ if (handleMemoryInputError(error)) return;
30112
+ throw error;
30113
+ }
30010
30114
  const { apiClient, auth, baseUrlOverridden } = await createAuthenticatedCliApiClient({
30011
30115
  apiKey: flags["api-key"],
30012
30116
  apiBaseUrl: flags["api-base-url"],
@@ -30015,15 +30119,7 @@ var MemoriesSearchCommand = class MemoriesSearchCommand extends Command {
30015
30119
  await runWithTiming(flags.time, async () => {
30016
30120
  const result = await searchMemories({
30017
30121
  client: apiClient.client,
30018
- query: {
30019
- ...args.prefix !== void 0 ? { prefix: args.prefix } : {},
30020
- limit: flags.limit,
30021
- ...flags.cursor ? { cursor: flags.cursor } : {},
30022
- ...flags["metadata-only"] ? { include_value: "false" } : {},
30023
- ...flags["updated-after"] ? { updated_after: flags["updated-after"] } : {},
30024
- ...flags["updated-before"] ? { updated_before: flags["updated-before"] } : {},
30025
- ...memoryScopeForQuery(flags)
30026
- },
30122
+ query,
30027
30123
  responseStyle: "fields"
30028
30124
  });
30029
30125
  if (result.error) {
package/man/primitive.1 CHANGED
@@ -77,6 +77,15 @@ Scaffold a Primitive Function.
77
77
  .B primitive functions deploy --name NAME --file PATH
78
78
  Deploy a Primitive Function bundle.
79
79
  .TP
80
+ .B primitive memories set KEY JSON
81
+ Store a durable JSON memory.
82
+ .TP
83
+ .B primitive memories get KEY
84
+ Read a durable memory by key.
85
+ .TP
86
+ .B primitive memories search PREFIX
87
+ List memories by key prefix.
88
+ .TP
80
89
  .B primitive list-operations
81
90
  Print the generated API operation manifest.
82
91
  .TP
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "primcli",
3
- "version": "1.17.0",
3
+ "version": "1.18.0",
4
4
  "description": "Official Primitive CLI: deploy Primitive Functions, send and inspect mail, manage endpoints, all from the terminal. Wraps the @primitivedotdev/sdk runtime client with one-shot commands.",
5
5
  "type": "module",
6
6
  "sideEffects": false,