bleam 0.0.11 → 0.0.13
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/ai.cjs +2315 -2173
- package/dist/ai.d.cts +227 -322
- package/dist/ai.d.ts +227 -322
- package/dist/ai.js +2310 -2159
- package/dist/app-storage-D8W4n8ey.cjs +39 -0
- package/dist/app-storage-Isi5Bo0R.js +34 -0
- package/dist/cli.cjs +148 -22
- package/dist/cli.d.cts +14 -1
- package/dist/cli.d.ts +13 -0
- package/dist/cli.js +148 -22
- package/dist/config.d.cts +1 -1
- package/dist/elements-CFk0QHw0.d.cts +127 -0
- package/dist/{ui-CHc4xEs_.d.ts → elements-ClGQ41Sc.d.ts} +84 -49
- package/dist/{ui.cjs → elements.cjs} +307 -168
- package/dist/elements.d.cts +2 -0
- package/dist/elements.d.ts +2 -0
- package/dist/{ui.js → elements.js} +306 -169
- package/dist/{files-Ds1wT8C2.js → files-DErLhzCB.js} +11 -12
- package/dist/{files-Bo7h9fik.cjs → files-lMk-CpL_.cjs} +16 -11
- package/dist/files.cjs +1 -1
- package/dist/files.d.cts +1 -1
- package/dist/files.js +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/schema-B7ELMpuI.js +226 -0
- package/dist/schema-B7SLUBLN.cjs +286 -0
- package/dist/schema-BWsDPc6c.d.cts +125 -0
- package/dist/schema-LxnzAfgw.d.ts +125 -0
- package/dist/schema.cjs +10 -2
- package/dist/schema.d.cts +2 -2
- package/dist/schema.d.ts +2 -2
- package/dist/schema.js +2 -2
- package/dist/secrets.cjs +146 -0
- package/dist/secrets.d.cts +14 -0
- package/dist/secrets.d.ts +14 -0
- package/dist/secrets.js +142 -0
- package/dist/state-BZYyrE2-.cjs +936 -0
- package/dist/state-DkaRFkZJ.js +843 -0
- package/dist/state.cjs +17 -12
- package/dist/state.d.cts +144 -140
- package/dist/state.d.ts +145 -140
- package/dist/state.js +4 -3
- package/dist/window.d.cts +1 -1
- package/dist/window.d.ts +3 -3
- package/package.json +13 -6
- package/templates/basic/app/index.tsx +2 -2
- package/templates/foundation-models/app/index.tsx +78 -16
- package/templates/image-generation/app/index.tsx +4 -4
- package/templates/native/ios/Bleam.xcodeproj/project.pbxproj +46 -46
- package/templates/native/ios/Podfile.lock +173 -173
- package/templates/native/modules/bleam-runtime/ios/AIModule.swift +42 -365
- package/templates/state/app/index.tsx +2 -2
- package/templates/text-generation/app/index.tsx +83 -52
- package/templates/updates/README.md +1 -1
- package/dist/schema-Bo5Jvqus.js +0 -90
- package/dist/schema-CYh6n8GS.d.ts +0 -58
- package/dist/schema-oeOrd3i1.d.cts +0 -58
- package/dist/schema-rQ13mrpD.cjs +0 -102
- package/dist/state-Bx0VlTlO.cjs +0 -852
- package/dist/state-CAwe-Vw1.js +0 -767
- package/dist/ui-1WepaMS4.d.cts +0 -92
- package/dist/ui.d.cts +0 -2
- package/dist/ui.d.ts +0 -2
- /package/dist/{config-CufOVJV3.d.cts → config-COcRnn5a.d.cts} +0 -0
- /package/dist/{files-Dt5mbzLq.d.cts → files-DwA7pzr3.d.cts} +0 -0
- /package/dist/{native-sqlite-yQLD5s9i.cjs → native-sqlite-Dw--FI9a.cjs} +0 -0
- /package/dist/{native-sqlite-xcGdamRD.js → native-sqlite-WzRNzCSh.js} +0 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
//#region src/schema.d.ts
|
|
2
|
+
type JSONValue = string | number | boolean | {
|
|
3
|
+
[key: string]: JSONValue;
|
|
4
|
+
} | JSONValue[];
|
|
5
|
+
type FieldValue = JSONValue;
|
|
6
|
+
type FieldToken = 'string' | 'number' | 'boolean';
|
|
7
|
+
type PrimitiveValue = string | number | boolean;
|
|
8
|
+
interface SchemaIssue {
|
|
9
|
+
message: string;
|
|
10
|
+
path?: ReadonlyArray<PropertyKey | {
|
|
11
|
+
key: PropertyKey;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
14
|
+
type SchemaResult<Output> = {
|
|
15
|
+
value: Output;
|
|
16
|
+
issues?: undefined;
|
|
17
|
+
} | {
|
|
18
|
+
issues: ReadonlyArray<SchemaIssue>;
|
|
19
|
+
};
|
|
20
|
+
interface StandardSchema<Input = unknown, Output = Input> {
|
|
21
|
+
readonly '~standard': {
|
|
22
|
+
readonly version: 1;
|
|
23
|
+
readonly vendor: string;
|
|
24
|
+
readonly validate: (value: unknown) => SchemaResult<Output>;
|
|
25
|
+
readonly types?: {
|
|
26
|
+
readonly input: Input;
|
|
27
|
+
readonly output: Output;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
interface FieldBase<Kind extends 'string' | 'number' | 'boolean' | 'literal' | 'object' | 'array', HasDefault$1 extends boolean> {
|
|
32
|
+
readonly kind: Kind;
|
|
33
|
+
readonly hasDefault: HasDefault$1;
|
|
34
|
+
}
|
|
35
|
+
interface StringField<HasDefault$1 extends boolean = boolean> extends FieldBase<'string', HasDefault$1> {
|
|
36
|
+
readonly defaultValue?: string;
|
|
37
|
+
}
|
|
38
|
+
interface NumberField<HasDefault$1 extends boolean = boolean> extends FieldBase<'number', HasDefault$1> {
|
|
39
|
+
readonly defaultValue?: number;
|
|
40
|
+
}
|
|
41
|
+
interface BooleanField<HasDefault$1 extends boolean = boolean> extends FieldBase<'boolean', HasDefault$1> {
|
|
42
|
+
readonly defaultValue?: boolean;
|
|
43
|
+
}
|
|
44
|
+
interface LiteralField<Value$1 extends PrimitiveValue = PrimitiveValue, HasDefault$1 extends boolean = boolean> extends FieldBase<'literal', HasDefault$1> {
|
|
45
|
+
readonly value: Value$1;
|
|
46
|
+
readonly defaultValue?: Value$1;
|
|
47
|
+
}
|
|
48
|
+
interface ObjectField<Shape$1 extends SchemaShape = SchemaShape, HasDefault$1 extends boolean = boolean> extends FieldBase<'object', HasDefault$1> {
|
|
49
|
+
readonly shape: Shape$1;
|
|
50
|
+
readonly defaultFactory?: () => SchemaInput<Shape$1>;
|
|
51
|
+
}
|
|
52
|
+
interface ArrayField<Item$1 extends FieldSchema = FieldSchema, HasDefault$1 extends boolean = boolean> extends FieldBase<'array', HasDefault$1> {
|
|
53
|
+
readonly item: Item$1;
|
|
54
|
+
readonly defaultFactory?: () => ReadonlyArray<FieldInput<Item$1>>;
|
|
55
|
+
}
|
|
56
|
+
type FieldSchema = StringField | NumberField | BooleanField | LiteralField | ObjectField | ArrayField;
|
|
57
|
+
type SchemaShape = Readonly<Record<string, FieldSchema>>;
|
|
58
|
+
type HasDefault<Field extends FieldSchema> = Field extends FieldBase<Field['kind'], infer Default> ? Default : false;
|
|
59
|
+
type FieldInput<Field extends FieldSchema> = Field extends StringField ? string : Field extends NumberField ? number : Field extends BooleanField ? boolean : Field extends LiteralField<infer Value> ? Value : Field extends ObjectField<infer Shape> ? SchemaInput<Shape> : Field extends ArrayField<infer Item> ? Array<FieldInput<Item>> : never;
|
|
60
|
+
type FieldOutput<Field extends FieldSchema> = Field extends StringField ? string : Field extends NumberField ? number : Field extends BooleanField ? boolean : Field extends LiteralField<infer Value> ? Value : Field extends ObjectField<infer Shape> ? SchemaOutput<Shape> : Field extends ArrayField<infer Item> ? Array<FieldOutput<Item>> : never;
|
|
61
|
+
type DefaultKeys<Shape$1 extends SchemaShape> = { [Key in keyof Shape$1]-?: HasDefault<Shape$1[Key]> extends true ? Key : never }[keyof Shape$1];
|
|
62
|
+
type OptionalKeys<Shape$1 extends SchemaShape> = Exclude<keyof Shape$1, DefaultKeys<Shape$1>>;
|
|
63
|
+
type SchemaInput<Shape$1 extends SchemaShape> = { [Key in keyof Shape$1]?: FieldInput<Shape$1[Key]> };
|
|
64
|
+
type SchemaOutput<Shape$1 extends SchemaShape> = { [Key in DefaultKeys<Shape$1>]: FieldOutput<Shape$1[Key]> } & { [Key in OptionalKeys<Shape$1>]?: FieldOutput<Shape$1[Key]> };
|
|
65
|
+
type DeepPartial<Value$1> = Value$1 extends ReadonlyArray<infer Item> ? Array<DeepPartial<Item>> : Value$1 extends object ? { [Key in keyof Value$1]?: DeepPartial<Value$1[Key]> } : Value$1;
|
|
66
|
+
type SchemaPatch<Shape$1 extends SchemaShape> = DeepPartial<SchemaInput<Shape$1>>;
|
|
67
|
+
type NestedFieldPath<Prefix extends string, Field extends FieldSchema> = Field extends ObjectField<infer Shape> ? `${Prefix}.${FieldPath<Shape>}` : never;
|
|
68
|
+
type FieldPath<Shape$1 extends SchemaShape> = { [Key in Extract<keyof Shape$1, string>]: Key | NestedFieldPath<Key, Shape$1[Key]> }[Extract<keyof Shape$1, string>];
|
|
69
|
+
type ValueAtPath<Shape$1 extends SchemaShape, Path extends string> = Path extends `${infer Key}.${infer Rest}` ? Key extends keyof Shape$1 ? Shape$1[Key] extends ObjectField<infer NestedShape> ? ValueAtPath<NestedShape, Rest> | (HasDefault<Shape$1[Key]> extends true ? never : undefined) : never : never : Path extends keyof Shape$1 ? FieldOutput<Shape$1[Path]> | (HasDefault<Shape$1[Path]> extends true ? never : undefined) : never;
|
|
70
|
+
type ValueAtFieldPath<Shape$1 extends SchemaShape, Path extends FieldPath<Shape$1>> = ValueAtPath<Shape$1, Path>;
|
|
71
|
+
type FieldAtPath<Shape$1 extends SchemaShape, Path extends string> = Path extends `${infer Key}.${infer Rest}` ? Key extends keyof Shape$1 ? Shape$1[Key] extends ObjectField<infer NestedShape> ? FieldAtPath<NestedShape, Rest> : never : never : Path extends keyof Shape$1 ? Shape$1[Path] : never;
|
|
72
|
+
type FieldAtFieldPath<Shape$1 extends SchemaShape, Path extends FieldPath<Shape$1>> = FieldAtPath<Shape$1, Path>;
|
|
73
|
+
type InferInput<Value$1 extends StandardSchema> = NonNullable<Value$1['~standard']['types']>['input'];
|
|
74
|
+
type InferOutput<Value$1 extends StandardSchema> = NonNullable<Value$1['~standard']['types']>['output'];
|
|
75
|
+
declare class SchemaError extends Error {
|
|
76
|
+
readonly issues: ReadonlyArray<SchemaIssue>;
|
|
77
|
+
constructor(issues: ReadonlyArray<SchemaIssue>);
|
|
78
|
+
}
|
|
79
|
+
type SchemaJSONSchema = {
|
|
80
|
+
type: FieldToken;
|
|
81
|
+
default?: PrimitiveValue;
|
|
82
|
+
} | {
|
|
83
|
+
type: FieldToken;
|
|
84
|
+
const: PrimitiveValue;
|
|
85
|
+
default?: PrimitiveValue;
|
|
86
|
+
} | {
|
|
87
|
+
type: 'array';
|
|
88
|
+
items: SchemaJSONSchema;
|
|
89
|
+
} | {
|
|
90
|
+
type: 'object';
|
|
91
|
+
properties: Record<string, SchemaJSONSchema>;
|
|
92
|
+
required: string[];
|
|
93
|
+
additionalProperties: false;
|
|
94
|
+
};
|
|
95
|
+
interface BleamSchema<Input, Output> extends StandardSchema<Input, Output> {
|
|
96
|
+
parse(value: unknown): Output;
|
|
97
|
+
safeParse(value: unknown): SchemaResult<Output>;
|
|
98
|
+
toJSONSchema(): Extract<SchemaJSONSchema, {
|
|
99
|
+
type: 'object';
|
|
100
|
+
}>;
|
|
101
|
+
transform<NextOutput>(transform: (value: Output) => NextOutput): BleamSchema<Input, NextOutput>;
|
|
102
|
+
}
|
|
103
|
+
type PrimitiveOptions<Value$1 extends PrimitiveValue> = {
|
|
104
|
+
default: Value$1;
|
|
105
|
+
};
|
|
106
|
+
type FactoryOptions<Value$1> = {
|
|
107
|
+
default: () => Value$1;
|
|
108
|
+
};
|
|
109
|
+
declare function string(): StringField<false>;
|
|
110
|
+
declare function string(options: PrimitiveOptions<string>): StringField<true>;
|
|
111
|
+
declare function number(): NumberField<false>;
|
|
112
|
+
declare function number(options: PrimitiveOptions<number>): NumberField<true>;
|
|
113
|
+
declare function boolean(): BooleanField<false>;
|
|
114
|
+
declare function boolean(options: PrimitiveOptions<boolean>): BooleanField<true>;
|
|
115
|
+
declare function literal<const Value$1 extends PrimitiveValue>(value: Value$1): LiteralField<Value$1, false>;
|
|
116
|
+
declare function literal<const Value$1 extends PrimitiveValue>(value: Value$1, options: PrimitiveOptions<Value$1>): LiteralField<Value$1, true>;
|
|
117
|
+
declare function object<const Shape$1 extends SchemaShape>(shape: Shape$1): ObjectField<Shape$1, false>;
|
|
118
|
+
declare function object<const Shape$1 extends SchemaShape>(shape: Shape$1, options: FactoryOptions<SchemaInput<Shape$1>>): ObjectField<Shape$1, true>;
|
|
119
|
+
declare function array<const Item$1 extends FieldSchema>(item: Item$1): ArrayField<Item$1, false>;
|
|
120
|
+
declare function array<const Item$1 extends FieldSchema>(item: Item$1, options: FactoryOptions<ReadonlyArray<FieldInput<Item$1>>>): ArrayField<Item$1, true>;
|
|
121
|
+
declare function schema<const Shape$1 extends SchemaShape>(shape: Shape$1): BleamSchema<SchemaInput<Shape$1>, SchemaOutput<Shape$1>>;
|
|
122
|
+
declare function getFieldSchema<Shape$1 extends SchemaShape, Path extends FieldPath<Shape$1>>(shape: Shape$1, path: Path): FieldAtFieldPath<Shape$1, Path>;
|
|
123
|
+
declare function getValueAtPath<Shape$1 extends SchemaShape, Path extends FieldPath<Shape$1>>(value: SchemaOutput<Shape$1>, path: Path): ValueAtFieldPath<Shape$1, Path>;
|
|
124
|
+
//#endregion
|
|
125
|
+
export { array as A, SchemaOutput as C, StandardSchema as D, SchemaShape as E, number as F, object as I, schema as L, getFieldSchema as M, getValueAtPath as N, StringField as O, literal as P, string as R, SchemaJSONSchema as S, SchemaResult as T, ObjectField as _, FieldAtFieldPath as a, SchemaInput as b, FieldPath as c, FieldValue as d, InferInput as f, NumberField as g, LiteralField as h, DeepPartial as i, boolean as j, ValueAtFieldPath as k, FieldSchema as l, JSONValue as m, BleamSchema as n, FieldInput as o, InferOutput as p, BooleanField as r, FieldOutput as s, ArrayField as t, FieldToken as u, PrimitiveValue as v, SchemaPatch as w, SchemaIssue as x, SchemaError as y };
|
package/dist/schema.cjs
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
const require_schema = require('./schema-
|
|
1
|
+
const require_schema = require('./schema-B7SLUBLN.cjs');
|
|
2
2
|
|
|
3
3
|
exports.SchemaError = require_schema.SchemaError;
|
|
4
|
-
exports.
|
|
4
|
+
exports.array = require_schema.array;
|
|
5
|
+
exports.boolean = require_schema.boolean;
|
|
6
|
+
exports.getFieldSchema = require_schema.getFieldSchema;
|
|
7
|
+
exports.getValueAtPath = require_schema.getValueAtPath;
|
|
8
|
+
exports.literal = require_schema.literal;
|
|
9
|
+
exports.number = require_schema.number;
|
|
10
|
+
exports.object = require_schema.object;
|
|
11
|
+
exports.schema = require_schema.schema;
|
|
12
|
+
exports.string = require_schema.string;
|
package/dist/schema.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { BleamSchema,
|
|
1
|
+
import { A as array, C as SchemaOutput, D as StandardSchema, E as SchemaShape, F as number, I as object, L as schema, M as getFieldSchema, N as getValueAtPath, O as StringField, P as literal, R as string, S as SchemaJSONSchema, T as SchemaResult, _ as ObjectField, a as FieldAtFieldPath, b as SchemaInput, c as FieldPath, d as FieldValue, f as InferInput, g as NumberField, h as LiteralField, i as DeepPartial, j as boolean, k as ValueAtFieldPath, l as FieldSchema, m as JSONValue, n as BleamSchema, o as FieldInput, p as InferOutput, r as BooleanField, s as FieldOutput, t as ArrayField, u as FieldToken, v as PrimitiveValue, w as SchemaPatch, x as SchemaIssue, y as SchemaError } from "./schema-BWsDPc6c.cjs";
|
|
2
|
+
export { ArrayField, BleamSchema, BooleanField, DeepPartial, FieldAtFieldPath, FieldInput, FieldOutput, FieldPath, FieldSchema, FieldToken, FieldValue, InferInput, InferOutput, JSONValue, LiteralField, NumberField, ObjectField, PrimitiveValue, SchemaError, SchemaInput, SchemaIssue, SchemaJSONSchema, SchemaOutput, SchemaPatch, SchemaResult, SchemaShape, StandardSchema, StringField, ValueAtFieldPath, array, boolean, getFieldSchema, getValueAtPath, literal, number, object, schema, string };
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { BleamSchema,
|
|
1
|
+
import { A as array, C as SchemaOutput, D as StandardSchema, E as SchemaShape, F as number, I as object, L as schema, M as getFieldSchema, N as getValueAtPath, O as StringField, P as literal, R as string, S as SchemaJSONSchema, T as SchemaResult, _ as ObjectField, a as FieldAtFieldPath, b as SchemaInput, c as FieldPath, d as FieldValue, f as InferInput, g as NumberField, h as LiteralField, i as DeepPartial, j as boolean, k as ValueAtFieldPath, l as FieldSchema, m as JSONValue, n as BleamSchema, o as FieldInput, p as InferOutput, r as BooleanField, s as FieldOutput, t as ArrayField, u as FieldToken, v as PrimitiveValue, w as SchemaPatch, x as SchemaIssue, y as SchemaError } from "./schema-LxnzAfgw.js";
|
|
2
|
+
export { ArrayField, BleamSchema, BooleanField, DeepPartial, FieldAtFieldPath, FieldInput, FieldOutput, FieldPath, FieldSchema, FieldToken, FieldValue, InferInput, InferOutput, JSONValue, LiteralField, NumberField, ObjectField, PrimitiveValue, SchemaError, SchemaInput, SchemaIssue, SchemaJSONSchema, SchemaOutput, SchemaPatch, SchemaResult, SchemaShape, StandardSchema, StringField, ValueAtFieldPath, array, boolean, getFieldSchema, getValueAtPath, literal, number, object, schema, string };
|
package/dist/schema.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as getValueAtPath, c as object, i as getFieldSchema, l as schema, n as array, o as literal, r as boolean, s as number, t as SchemaError, u as string } from "./schema-B7ELMpuI.js";
|
|
2
2
|
|
|
3
|
-
export { SchemaError, schema };
|
|
3
|
+
export { SchemaError, array, boolean, getFieldSchema, getValueAtPath, literal, number, object, schema, string };
|
package/dist/secrets.cjs
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
const require_native_runtime = require('./native-runtime-CsXnXkQn.cjs');
|
|
2
|
+
const require_app_storage = require('./app-storage-D8W4n8ey.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/native-secrets.ts
|
|
5
|
+
var NativeSecretsError = class extends Error {
|
|
6
|
+
constructor(status, message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.name = "NativeSecretsError";
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
let securityLoaded = false;
|
|
13
|
+
function ensureSecurity() {
|
|
14
|
+
if (securityLoaded) return;
|
|
15
|
+
const nativeScript = require_native_runtime.ensureNativeScript();
|
|
16
|
+
if (!nativeScript.isFrameworkLoaded("Security") && !nativeScript.loadFramework("Security")) throw new NativeSecretsError(void 0, "Keychain is unavailable");
|
|
17
|
+
securityLoaded = true;
|
|
18
|
+
}
|
|
19
|
+
function dictionary(capacity) {
|
|
20
|
+
return NSMutableDictionary.dictionaryWithCapacity(capacity);
|
|
21
|
+
}
|
|
22
|
+
function set(target, key, value) {
|
|
23
|
+
target.setObjectForKey(value, key);
|
|
24
|
+
}
|
|
25
|
+
function serviceName() {
|
|
26
|
+
return NSString.stringWithString(`dev.bleam.apps.${require_app_storage.currentAppStorageKey()}.secrets`);
|
|
27
|
+
}
|
|
28
|
+
function baseQuery(key) {
|
|
29
|
+
ensureSecurity();
|
|
30
|
+
const query = dictionary(4);
|
|
31
|
+
set(query, kSecClass, kSecClassGenericPassword);
|
|
32
|
+
set(query, kSecAttrService, serviceName());
|
|
33
|
+
set(query, kSecAttrAccount, NSString.stringWithString(key));
|
|
34
|
+
set(query, kSecUseDataProtectionKeychain, NSNumber.numberWithBool(true));
|
|
35
|
+
return query;
|
|
36
|
+
}
|
|
37
|
+
function statusMessage(status) {
|
|
38
|
+
const message = SecCopyErrorMessageString(status, null);
|
|
39
|
+
return message ? String(message) : `Keychain operation failed (${status})`;
|
|
40
|
+
}
|
|
41
|
+
function failure(status) {
|
|
42
|
+
return new NativeSecretsError(status, statusMessage(status));
|
|
43
|
+
}
|
|
44
|
+
function nativeSetItem(key, value) {
|
|
45
|
+
const query = baseQuery(key);
|
|
46
|
+
const encoded = NSString.stringWithString(value).dataUsingEncoding(NSUTF8StringEncoding);
|
|
47
|
+
const update = dictionary(1);
|
|
48
|
+
set(update, kSecValueData, encoded);
|
|
49
|
+
const updateStatus = SecItemUpdate(query, update);
|
|
50
|
+
if (updateStatus === errSecSuccess) return;
|
|
51
|
+
if (updateStatus !== errSecItemNotFound) throw failure(updateStatus);
|
|
52
|
+
set(query, kSecValueData, encoded);
|
|
53
|
+
set(query, kSecAttrAccessible, kSecAttrAccessibleWhenUnlockedThisDeviceOnly);
|
|
54
|
+
const addStatus = SecItemAdd(query, null);
|
|
55
|
+
if (addStatus === errSecSuccess) return;
|
|
56
|
+
if (addStatus === errSecDuplicateItem) {
|
|
57
|
+
const retryStatus = SecItemUpdate(baseQuery(key), update);
|
|
58
|
+
if (retryStatus === errSecSuccess) return;
|
|
59
|
+
throw failure(retryStatus);
|
|
60
|
+
}
|
|
61
|
+
throw failure(addStatus);
|
|
62
|
+
}
|
|
63
|
+
function nativeGetItem(key) {
|
|
64
|
+
const query = baseQuery(key);
|
|
65
|
+
set(query, kSecReturnData, NSNumber.numberWithBool(true));
|
|
66
|
+
set(query, kSecMatchLimit, kSecMatchLimitOne);
|
|
67
|
+
const result = new interop.Reference();
|
|
68
|
+
const status = SecItemCopyMatching(query, result);
|
|
69
|
+
if (status === errSecItemNotFound) return void 0;
|
|
70
|
+
if (status !== errSecSuccess) throw failure(status);
|
|
71
|
+
if (!result.value) throw new NativeSecretsError(errSecDecode, "Keychain returned invalid data");
|
|
72
|
+
const decoded = NSString.alloc().initWithDataEncoding(result.value, NSUTF8StringEncoding);
|
|
73
|
+
if (!decoded) throw new NativeSecretsError(errSecDecode, "Keychain returned invalid data");
|
|
74
|
+
return String(decoded);
|
|
75
|
+
}
|
|
76
|
+
function nativeHasItem(key) {
|
|
77
|
+
const status = SecItemCopyMatching(baseQuery(key), null);
|
|
78
|
+
if (status === errSecSuccess) return true;
|
|
79
|
+
if (status === errSecItemNotFound) return false;
|
|
80
|
+
throw failure(status);
|
|
81
|
+
}
|
|
82
|
+
function nativeRemoveItem(key) {
|
|
83
|
+
const status = SecItemDelete(baseQuery(key));
|
|
84
|
+
if (status === errSecSuccess || status === errSecItemNotFound) return;
|
|
85
|
+
throw failure(status);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/secrets.ts
|
|
90
|
+
var SecretsError = class extends Error {
|
|
91
|
+
constructor(code, message, status, cause) {
|
|
92
|
+
super(message);
|
|
93
|
+
this.code = code;
|
|
94
|
+
this.status = status;
|
|
95
|
+
this.cause = cause;
|
|
96
|
+
this.name = "SecretsError";
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
function validateKey(key) {
|
|
100
|
+
if (typeof key !== "string" || key.trim().length === 0) throw new SecretsError("invalid_key", "Secret key must not be empty");
|
|
101
|
+
}
|
|
102
|
+
function mapError(error) {
|
|
103
|
+
if (error instanceof SecretsError) return error;
|
|
104
|
+
if (!(error instanceof NativeSecretsError)) return new SecretsError("operation_failed", "Keychain operation failed", void 0, error);
|
|
105
|
+
return new SecretsError(error.status === void 0 || error.status === errSecNotAvailable ? "unavailable" : error.status === errSecInteractionNotAllowed ? "interaction_not_allowed" : error.status === errSecAuthFailed || error.status === errSecUserCanceled ? "authentication_failed" : error.status === errSecMissingEntitlement || error.status === errSecNoAccessForItem ? "permission_denied" : error.status === errSecDecode ? "invalid_data" : "operation_failed", error.message, error.status, error);
|
|
106
|
+
}
|
|
107
|
+
async function setItem(key, value) {
|
|
108
|
+
validateKey(key);
|
|
109
|
+
if (typeof value !== "string") throw new SecretsError("invalid_value", "Secret value must be a string");
|
|
110
|
+
try {
|
|
111
|
+
nativeSetItem(key, value);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
throw mapError(error);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async function getItem(key) {
|
|
117
|
+
validateKey(key);
|
|
118
|
+
try {
|
|
119
|
+
return nativeGetItem(key);
|
|
120
|
+
} catch (error) {
|
|
121
|
+
throw mapError(error);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async function hasItem(key) {
|
|
125
|
+
validateKey(key);
|
|
126
|
+
try {
|
|
127
|
+
return nativeHasItem(key);
|
|
128
|
+
} catch (error) {
|
|
129
|
+
throw mapError(error);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async function removeItem(key) {
|
|
133
|
+
validateKey(key);
|
|
134
|
+
try {
|
|
135
|
+
nativeRemoveItem(key);
|
|
136
|
+
} catch (error) {
|
|
137
|
+
throw mapError(error);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
//#endregion
|
|
142
|
+
exports.SecretsError = SecretsError;
|
|
143
|
+
exports.getItem = getItem;
|
|
144
|
+
exports.hasItem = hasItem;
|
|
145
|
+
exports.removeItem = removeItem;
|
|
146
|
+
exports.setItem = setItem;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/secrets.d.ts
|
|
2
|
+
type SecretsErrorCode = 'invalid_key' | 'invalid_value' | 'unavailable' | 'interaction_not_allowed' | 'authentication_failed' | 'permission_denied' | 'invalid_data' | 'operation_failed';
|
|
3
|
+
declare class SecretsError extends Error {
|
|
4
|
+
readonly code: SecretsErrorCode;
|
|
5
|
+
readonly status?: number | undefined;
|
|
6
|
+
readonly cause?: unknown | undefined;
|
|
7
|
+
constructor(code: SecretsErrorCode, message: string, status?: number | undefined, cause?: unknown | undefined);
|
|
8
|
+
}
|
|
9
|
+
declare function setItem(key: string, value: string): Promise<void>;
|
|
10
|
+
declare function getItem(key: string): Promise<string | undefined>;
|
|
11
|
+
declare function hasItem(key: string): Promise<boolean>;
|
|
12
|
+
declare function removeItem(key: string): Promise<void>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { SecretsError, SecretsErrorCode, getItem, hasItem, removeItem, setItem };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/secrets.d.ts
|
|
2
|
+
type SecretsErrorCode = 'invalid_key' | 'invalid_value' | 'unavailable' | 'interaction_not_allowed' | 'authentication_failed' | 'permission_denied' | 'invalid_data' | 'operation_failed';
|
|
3
|
+
declare class SecretsError extends Error {
|
|
4
|
+
readonly code: SecretsErrorCode;
|
|
5
|
+
readonly status?: number | undefined;
|
|
6
|
+
readonly cause?: unknown | undefined;
|
|
7
|
+
constructor(code: SecretsErrorCode, message: string, status?: number | undefined, cause?: unknown | undefined);
|
|
8
|
+
}
|
|
9
|
+
declare function setItem(key: string, value: string): Promise<void>;
|
|
10
|
+
declare function getItem(key: string): Promise<string | undefined>;
|
|
11
|
+
declare function hasItem(key: string): Promise<boolean>;
|
|
12
|
+
declare function removeItem(key: string): Promise<void>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { SecretsError, SecretsErrorCode, getItem, hasItem, removeItem, setItem };
|
package/dist/secrets.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { t as ensureNativeScript } from "./native-runtime-C85Nuc4F.js";
|
|
2
|
+
import { t as currentAppStorageKey } from "./app-storage-Isi5Bo0R.js";
|
|
3
|
+
|
|
4
|
+
//#region src/native-secrets.ts
|
|
5
|
+
var NativeSecretsError = class extends Error {
|
|
6
|
+
constructor(status, message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.name = "NativeSecretsError";
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
let securityLoaded = false;
|
|
13
|
+
function ensureSecurity() {
|
|
14
|
+
if (securityLoaded) return;
|
|
15
|
+
const nativeScript = ensureNativeScript();
|
|
16
|
+
if (!nativeScript.isFrameworkLoaded("Security") && !nativeScript.loadFramework("Security")) throw new NativeSecretsError(void 0, "Keychain is unavailable");
|
|
17
|
+
securityLoaded = true;
|
|
18
|
+
}
|
|
19
|
+
function dictionary(capacity) {
|
|
20
|
+
return NSMutableDictionary.dictionaryWithCapacity(capacity);
|
|
21
|
+
}
|
|
22
|
+
function set(target, key, value) {
|
|
23
|
+
target.setObjectForKey(value, key);
|
|
24
|
+
}
|
|
25
|
+
function serviceName() {
|
|
26
|
+
return NSString.stringWithString(`dev.bleam.apps.${currentAppStorageKey()}.secrets`);
|
|
27
|
+
}
|
|
28
|
+
function baseQuery(key) {
|
|
29
|
+
ensureSecurity();
|
|
30
|
+
const query = dictionary(4);
|
|
31
|
+
set(query, kSecClass, kSecClassGenericPassword);
|
|
32
|
+
set(query, kSecAttrService, serviceName());
|
|
33
|
+
set(query, kSecAttrAccount, NSString.stringWithString(key));
|
|
34
|
+
set(query, kSecUseDataProtectionKeychain, NSNumber.numberWithBool(true));
|
|
35
|
+
return query;
|
|
36
|
+
}
|
|
37
|
+
function statusMessage(status) {
|
|
38
|
+
const message = SecCopyErrorMessageString(status, null);
|
|
39
|
+
return message ? String(message) : `Keychain operation failed (${status})`;
|
|
40
|
+
}
|
|
41
|
+
function failure(status) {
|
|
42
|
+
return new NativeSecretsError(status, statusMessage(status));
|
|
43
|
+
}
|
|
44
|
+
function nativeSetItem(key, value) {
|
|
45
|
+
const query = baseQuery(key);
|
|
46
|
+
const encoded = NSString.stringWithString(value).dataUsingEncoding(NSUTF8StringEncoding);
|
|
47
|
+
const update = dictionary(1);
|
|
48
|
+
set(update, kSecValueData, encoded);
|
|
49
|
+
const updateStatus = SecItemUpdate(query, update);
|
|
50
|
+
if (updateStatus === errSecSuccess) return;
|
|
51
|
+
if (updateStatus !== errSecItemNotFound) throw failure(updateStatus);
|
|
52
|
+
set(query, kSecValueData, encoded);
|
|
53
|
+
set(query, kSecAttrAccessible, kSecAttrAccessibleWhenUnlockedThisDeviceOnly);
|
|
54
|
+
const addStatus = SecItemAdd(query, null);
|
|
55
|
+
if (addStatus === errSecSuccess) return;
|
|
56
|
+
if (addStatus === errSecDuplicateItem) {
|
|
57
|
+
const retryStatus = SecItemUpdate(baseQuery(key), update);
|
|
58
|
+
if (retryStatus === errSecSuccess) return;
|
|
59
|
+
throw failure(retryStatus);
|
|
60
|
+
}
|
|
61
|
+
throw failure(addStatus);
|
|
62
|
+
}
|
|
63
|
+
function nativeGetItem(key) {
|
|
64
|
+
const query = baseQuery(key);
|
|
65
|
+
set(query, kSecReturnData, NSNumber.numberWithBool(true));
|
|
66
|
+
set(query, kSecMatchLimit, kSecMatchLimitOne);
|
|
67
|
+
const result = new interop.Reference();
|
|
68
|
+
const status = SecItemCopyMatching(query, result);
|
|
69
|
+
if (status === errSecItemNotFound) return void 0;
|
|
70
|
+
if (status !== errSecSuccess) throw failure(status);
|
|
71
|
+
if (!result.value) throw new NativeSecretsError(errSecDecode, "Keychain returned invalid data");
|
|
72
|
+
const decoded = NSString.alloc().initWithDataEncoding(result.value, NSUTF8StringEncoding);
|
|
73
|
+
if (!decoded) throw new NativeSecretsError(errSecDecode, "Keychain returned invalid data");
|
|
74
|
+
return String(decoded);
|
|
75
|
+
}
|
|
76
|
+
function nativeHasItem(key) {
|
|
77
|
+
const status = SecItemCopyMatching(baseQuery(key), null);
|
|
78
|
+
if (status === errSecSuccess) return true;
|
|
79
|
+
if (status === errSecItemNotFound) return false;
|
|
80
|
+
throw failure(status);
|
|
81
|
+
}
|
|
82
|
+
function nativeRemoveItem(key) {
|
|
83
|
+
const status = SecItemDelete(baseQuery(key));
|
|
84
|
+
if (status === errSecSuccess || status === errSecItemNotFound) return;
|
|
85
|
+
throw failure(status);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/secrets.ts
|
|
90
|
+
var SecretsError = class extends Error {
|
|
91
|
+
constructor(code, message, status, cause) {
|
|
92
|
+
super(message);
|
|
93
|
+
this.code = code;
|
|
94
|
+
this.status = status;
|
|
95
|
+
this.cause = cause;
|
|
96
|
+
this.name = "SecretsError";
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
function validateKey(key) {
|
|
100
|
+
if (typeof key !== "string" || key.trim().length === 0) throw new SecretsError("invalid_key", "Secret key must not be empty");
|
|
101
|
+
}
|
|
102
|
+
function mapError(error) {
|
|
103
|
+
if (error instanceof SecretsError) return error;
|
|
104
|
+
if (!(error instanceof NativeSecretsError)) return new SecretsError("operation_failed", "Keychain operation failed", void 0, error);
|
|
105
|
+
return new SecretsError(error.status === void 0 || error.status === errSecNotAvailable ? "unavailable" : error.status === errSecInteractionNotAllowed ? "interaction_not_allowed" : error.status === errSecAuthFailed || error.status === errSecUserCanceled ? "authentication_failed" : error.status === errSecMissingEntitlement || error.status === errSecNoAccessForItem ? "permission_denied" : error.status === errSecDecode ? "invalid_data" : "operation_failed", error.message, error.status, error);
|
|
106
|
+
}
|
|
107
|
+
async function setItem(key, value) {
|
|
108
|
+
validateKey(key);
|
|
109
|
+
if (typeof value !== "string") throw new SecretsError("invalid_value", "Secret value must be a string");
|
|
110
|
+
try {
|
|
111
|
+
nativeSetItem(key, value);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
throw mapError(error);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async function getItem(key) {
|
|
117
|
+
validateKey(key);
|
|
118
|
+
try {
|
|
119
|
+
return nativeGetItem(key);
|
|
120
|
+
} catch (error) {
|
|
121
|
+
throw mapError(error);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async function hasItem(key) {
|
|
125
|
+
validateKey(key);
|
|
126
|
+
try {
|
|
127
|
+
return nativeHasItem(key);
|
|
128
|
+
} catch (error) {
|
|
129
|
+
throw mapError(error);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async function removeItem(key) {
|
|
133
|
+
validateKey(key);
|
|
134
|
+
try {
|
|
135
|
+
nativeRemoveItem(key);
|
|
136
|
+
} catch (error) {
|
|
137
|
+
throw mapError(error);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
//#endregion
|
|
142
|
+
export { SecretsError, getItem, hasItem, removeItem, setItem };
|