@spencerls/react-native-nfc 1.0.8 → 1.0.9

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/index.d.ts CHANGED
@@ -1,105 +1,46 @@
1
1
  import * as react_native_nfc_manager from 'react-native-nfc-manager';
2
- import { TagEvent, NfcTech, NdefRecord } from 'react-native-nfc-manager';
2
+ import { NdefRecord, ISOLangCode, TNF, TagEvent, NfcTech, NdefStatus } from 'react-native-nfc-manager';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import { PropsWithChildren } from 'react';
5
5
 
6
- declare const operations$2: {
7
- transceive(data: number[]): Promise<number[]>;
8
- };
9
-
10
- declare const utils$2: {};
11
-
12
- declare namespace index$2 {
13
- export { operations$2 as operations, utils$2 as utils };
6
+ declare class Builder {
7
+ static records(b: NdefBuilder): NdefRecord[];
8
+ static message(b: NdefBuilder): number[];
9
+ static record(init: BuildRecordInit): NdefRecord;
10
+ static textRecord(text: string, lang?: ISOLangCode, encoding?: "utf8" | "utf16", id?: string): NdefRecord;
11
+ static uriRecord(uri: string, id?: string): NdefRecord;
12
+ static jsonRecord(payload: string | Uint8Array | number[], id?: string): NdefRecord;
13
+ static mimeRecord(mimeType: string, payload: string | Uint8Array | number[], id?: string): NdefRecord;
14
+ static externalRecord(domain: string, type: string, payload: string | Uint8Array | number[], id?: string): NdefRecord;
15
+ static createEmpty(): NdefRecord;
14
16
  }
15
17
 
16
- type StrictTagEvent = TagEvent & {
17
- id: string;
18
- };
19
-
20
- declare const operations$1: {
21
- withVTag<T>(handler: (tag: StrictTagEvent) => Promise<T>): Promise<T>;
22
- writeBlockNfcV(blockNumber: number, data: Uint8Array): Promise<void>;
23
- readBlockNfcV(blockNumber: number): Promise<Uint8Array<ArrayBufferLike>>;
24
- getSystemInfoNfcV(): Promise<any>;
25
- };
26
-
27
- declare const utils$1: {
28
- readonly tech: NfcTech.NfcV | NfcTech[];
29
- readonly Flags: {
30
- readonly HIGH_DATA_RATE: 2;
31
- readonly ADDRESSED: 32;
32
- };
33
- readonly Commands: {
34
- readonly READ_SINGLE_BLOCK: 32;
35
- readonly WRITE_SINGLE_BLOCK: 33;
36
- readonly GET_SYSTEM_INFO: 43;
37
- };
38
- /**
39
- * Combine multiple flag bits into one byte.
40
- * Example: Flags.ADDRESSED | Flags.HIGH_DATA_RATE
41
- */
42
- readonly flags: (...bits: number[]) => number;
43
- /**
44
- * Convert tag.id hex string (MSB->LSB) into reversed byte array (LSB->MSB)
45
- * ISO15693 requires reversed UID for addressed commands.
46
- */
47
- readonly reverseUid: (tagIdHex: string) => number[];
48
- /**
49
- * Build READ_SINGLE_BLOCK command.
50
- * FLAGS: addressed + high data rate by default.
51
- */
52
- readonly buildReadBlock: (uidReversed: number[], blockNumber: number) => number[];
53
- /**
54
- * Build WRITE_SINGLE_BLOCK command.
55
- * Note: data must match the block size (usually 4 or 8 bytes).
56
- */
57
- readonly buildWriteBlock: (uidReversed: number[], blockNumber: number, data: Uint8Array) => number[];
58
- /**
59
- * Build GET_SYSTEM_INFO command.
60
- */
61
- readonly buildGetSystemInfo: (uidReversed: number[]) => number[];
62
- /**
63
- * Parse a READ_SINGLE_BLOCK response.
64
- * Response format:
65
- * - byte[0] = status (0x00 = success)
66
- * - byte[1..] = block payload bytes
67
- */
68
- readonly parseReadResponse: (resp: number[]) => Uint8Array;
69
- /**
70
- * Parse WRITE_SINGLE_BLOCK response.
71
- * Successful write has resp[0] === 0x00.
72
- */
73
- readonly parseWriteResponse: (resp: number[]) => void;
74
- /**
75
- * Parse GET_SYSTEM_INFO response.
76
- * Returns: UID, DSFID, AFI, numberOfBlocks, blockSize, manufacturer
77
- */
78
- readonly parseSystemInfo: (resp: number[]) => any;
79
- /** Identify common manufacturers based on UID prefix */
80
- readonly detectManufacturer: (uid: string) => string;
81
- };
82
-
83
- declare namespace index$1 {
84
- export { operations$1 as operations, utils$1 as utils };
18
+ type NdefBuilder = (r: typeof Builder) => NdefRecord[];
19
+ interface BuildRecordInit {
20
+ tnf: TNF;
21
+ type: string | number[];
22
+ id?: string | number[];
23
+ payload?: string | number[];
24
+ }
25
+ interface NdefMessageResult {
26
+ ndefMessage: NdefRecord[];
27
+ type: number;
28
+ maxSize: number;
29
+ isWritable: boolean;
30
+ canMakeReadOnly: boolean;
85
31
  }
86
32
 
87
- declare const operations: {
88
- writeNdef(records: NdefRecord[]): Promise<void>;
89
- writeTextNdef(text: string): Promise<void>;
90
- writeUriNdef(uri: string): Promise<void>;
33
+ type SystemInfo = {
34
+ uid?: string;
35
+ dsfid?: number;
36
+ afi?: number;
37
+ numberOfBlocks?: number;
38
+ blockSize?: number;
39
+ icReference?: number;
40
+ manufacturer?: string;
91
41
  };
92
42
 
93
- declare const utils: {};
94
-
95
- declare const index_operations: typeof operations;
96
- declare const index_utils: typeof utils;
97
- declare namespace index {
98
- export { index_operations as operations, index_utils as utils };
99
- }
100
-
101
43
  type NfcMode = "idle" | "starting" | "active" | "stopping" | "technology";
102
-
103
44
  interface NfcState {
104
45
  mode: NfcMode;
105
46
  tag: TagEvent | null;
@@ -129,54 +70,162 @@ declare class NfcService {
129
70
  }
130
71
  declare const nfcService: NfcService;
131
72
 
73
+ declare function readMessage$1(): Promise<NdefMessageResult>;
74
+ declare function write$1(records: NdefRecord[]): Promise<void>;
75
+
76
+ declare const nfcNdefTag: {
77
+ readonly tech: react_native_nfc_manager.NfcTech[];
78
+ readonly readMessage: typeof readMessage$1;
79
+ readonly write: typeof write$1;
80
+ };
81
+
82
+ declare function getStatus(): Promise<{
83
+ status: NdefStatus;
84
+ capacity: number;
85
+ }>;
86
+ declare function readMessage(): Promise<NdefMessageResult>;
87
+ declare function readFull(): Promise<{
88
+ message: NdefMessageResult;
89
+ tag: TagEvent;
90
+ }>;
91
+ declare function write(records: NdefRecord[]): Promise<void>;
92
+ declare function writeText(text: string, lang?: ISOLangCode, encoding?: "utf8" | "utf16", id?: string): Promise<void>;
93
+ declare function writeUri(uri: string, id?: string): Promise<void>;
94
+ declare function writeJson(data: unknown, id?: string): Promise<void>;
95
+ declare function writeMime(mimeType: string, payload: string | Uint8Array | number[], id?: string): Promise<void>;
96
+ declare function writeExternal(domain: string, type: string, payload: string | Uint8Array | number[], id?: string): Promise<void>;
97
+ declare function makeReadOnly(): Promise<void>;
98
+
99
+ declare function getTag$1(): Promise<react_native_nfc_manager.TagEvent>;
100
+
101
+ declare const nfcTag: {
102
+ readonly getTag: typeof getTag$1;
103
+ };
104
+
105
+ declare function getTag(tech: NfcTech | NfcTech[]): Promise<TagEvent>;
106
+
107
+ declare function transceive(bytes: number[]): Promise<number[]>;
108
+ declare function readBlock$1(tagId: string, blockNumber: number): Promise<Uint8Array>;
109
+ declare function readBlocks$1(tagId: string, startBlock: number, endBlock: number): Promise<Uint8Array<ArrayBuffer>>;
110
+ declare function writeBlock$1(tagId: string, blockNumber: number, data: Uint8Array): Promise<void>;
111
+ declare function writeBlocks$1(tagId: string, blockNumber: number, data: Uint8Array[]): Promise<void>;
112
+ declare function getSystemInfo$1(): Promise<SystemInfo>;
113
+
114
+ declare const FLAGS: {
115
+ HIGH_DATA_RATE: number;
116
+ ADDRESSED: number;
117
+ };
118
+ declare const COMMANDS: {
119
+ READ_SINGLE_BLOCK: number;
120
+ WRITE_SINGLE_BLOCK: number;
121
+ GET_SYSTEM_INFO: number;
122
+ };
123
+ /**
124
+ * Combine multiple flag bits into one byte.
125
+ * Example: Flags.ADDRESSED | Flags.HIGH_DATA_RATE
126
+ */
127
+ declare function buildFlags(...bits: number[]): number;
128
+ /**
129
+ * Convert tag.id hex string (MSB->LSB) into reversed byte array (LSB->MSB)
130
+ * ISO15693 requires reversed UID for addressed commands.
131
+ */
132
+ declare function reverseUid(tagIdHex: string): number[];
133
+ /**
134
+ * Build READ_SINGLE_BLOCK command.
135
+ * FLAGS: addressed + high data rate by default.
136
+ */
137
+ declare function buildReadBlock(uidReversed: number[], blockNumber: number): number[];
138
+ /**
139
+ * Build WRITE_SINGLE_BLOCK command.
140
+ * Note: data must match the block size (usually 4 or 8 bytes).
141
+ */
142
+ declare function buildWriteBlock(uidReversed: number[], blockNumber: number, data: Uint8Array): number[];
143
+ /**
144
+ * Build GET_SYSTEM_INFO command.
145
+ */
146
+ declare function buildGetSystemInfo(): number[];
147
+ /**
148
+ * Parse a READ_SINGLE_BLOCK response.
149
+ * Response format:
150
+ * - byte[0] = status (0x00 = success)
151
+ * - byte[1..] = block payload bytes
152
+ */
153
+ declare function parseReadResponse(resp: number[]): Uint8Array;
154
+ /**
155
+ * Parse WRITE_SINGLE_BLOCK response.
156
+ * Successful write has resp[0] === 0x00.
157
+ */
158
+ declare function parseWriteResponse(resp: number[]): void;
159
+ /**
160
+ * Parse GET_SYSTEM_INFO response.
161
+ * Returns: UID, DSFID, AFI, numberOfBlocks, blockSize, manufacturer
162
+ */
163
+ declare function parseSystemInfo(resp: number[]): SystemInfo;
164
+ /** Identify common manufacturers based on UID prefix */
165
+ declare function detectManufacturer(uid: string): string;
166
+
167
+ declare const utils_COMMANDS: typeof COMMANDS;
168
+ declare const utils_FLAGS: typeof FLAGS;
169
+ declare const utils_buildFlags: typeof buildFlags;
170
+ declare const utils_buildGetSystemInfo: typeof buildGetSystemInfo;
171
+ declare const utils_buildReadBlock: typeof buildReadBlock;
172
+ declare const utils_buildWriteBlock: typeof buildWriteBlock;
173
+ declare const utils_detectManufacturer: typeof detectManufacturer;
174
+ declare const utils_parseReadResponse: typeof parseReadResponse;
175
+ declare const utils_parseSystemInfo: typeof parseSystemInfo;
176
+ declare const utils_parseWriteResponse: typeof parseWriteResponse;
177
+ declare const utils_reverseUid: typeof reverseUid;
178
+ declare namespace utils {
179
+ export { utils_COMMANDS as COMMANDS, utils_FLAGS as FLAGS, utils_buildFlags as buildFlags, utils_buildGetSystemInfo as buildGetSystemInfo, utils_buildReadBlock as buildReadBlock, utils_buildWriteBlock as buildWriteBlock, utils_detectManufacturer as detectManufacturer, utils_parseReadResponse as parseReadResponse, utils_parseSystemInfo as parseSystemInfo, utils_parseWriteResponse as parseWriteResponse, utils_reverseUid as reverseUid };
180
+ }
181
+
182
+ declare const nfcVTag: {
183
+ readonly tech: react_native_nfc_manager.NfcTech.NfcV | react_native_nfc_manager.NfcTech[];
184
+ readonly utils: typeof utils;
185
+ readonly transceive: typeof transceive;
186
+ readonly readBlock: typeof readBlock$1;
187
+ readonly readBlocks: typeof readBlocks$1;
188
+ readonly writeBlock: typeof writeBlock$1;
189
+ readonly writeBlocks: typeof writeBlocks$1;
190
+ readonly getSystemInfo: typeof getSystemInfo$1;
191
+ };
192
+
193
+ declare function writeBlock(blockNumber: number, data: Uint8Array): Promise<void>;
194
+ declare function writeBlocks(blockNumber: number, data: Uint8Array[]): Promise<void>;
195
+ declare function readBlock(blockNumber: number): Promise<Uint8Array>;
196
+ declare function readBlocks(startBlock: number, endBlock: number): Promise<Uint8Array>;
197
+ declare function getSystemInfo(): Promise<SystemInfo>;
198
+
132
199
  /**
133
200
  * NFC root namespace providing access to:
134
201
  * - NfcService
135
202
  * - ISO15693 NFC-V ops
136
- * - NFC-A ops
137
203
  * - NDEF operations
138
204
  */
139
205
  declare const nfc: {
140
206
  readonly service: NfcService;
141
- /** ISO15693 protocol helpers and high-level operations */
142
207
  readonly v: {
143
- readonly utils: {
144
- readonly tech: react_native_nfc_manager.NfcTech.NfcV | react_native_nfc_manager.NfcTech[];
145
- readonly Flags: {
146
- readonly HIGH_DATA_RATE: 2;
147
- readonly ADDRESSED: 32;
148
- };
149
- readonly Commands: {
150
- readonly READ_SINGLE_BLOCK: 32;
151
- readonly WRITE_SINGLE_BLOCK: 33;
152
- readonly GET_SYSTEM_INFO: 43;
153
- };
154
- readonly flags: (...bits: number[]) => number;
155
- readonly reverseUid: (tagIdHex: string) => number[];
156
- readonly buildReadBlock: (uidReversed: number[], blockNumber: number) => number[];
157
- readonly buildWriteBlock: (uidReversed: number[], blockNumber: number, data: Uint8Array) => number[];
158
- readonly buildGetSystemInfo: (uidReversed: number[]) => number[];
159
- readonly parseReadResponse: (resp: number[]) => Uint8Array;
160
- readonly parseWriteResponse: (resp: number[]) => void;
161
- readonly parseSystemInfo: (resp: number[]) => any;
162
- readonly detectManufacturer: (uid: string) => string;
163
- };
164
- readonly withVTag: <T>(handler: (tag: StrictTagEvent) => Promise<T>) => Promise<T>;
165
- readonly writeBlockNfcV: (blockNumber: number, data: Uint8Array) => Promise<void>;
166
- readonly readBlockNfcV: (blockNumber: number) => Promise<Uint8Array<ArrayBufferLike>>;
167
- readonly getSystemInfoNfcV: () => Promise<any>;
168
- };
169
- /** NFC-A / Type 2 helpers and operations */
170
- readonly a: {
171
- readonly utils: {};
172
- readonly transceive: (data: number[]) => Promise<number[]>;
208
+ readonly writeBlock: typeof writeBlock;
209
+ readonly writeBlocks: typeof writeBlocks;
210
+ readonly readBlock: typeof readBlock;
211
+ readonly readBlocks: typeof readBlocks;
212
+ readonly getSystemInfo: typeof getSystemInfo;
173
213
  };
174
- /** NDEF read/write utilities and operations */
175
214
  readonly ndef: {
176
- readonly utils: {};
177
- readonly writeNdef: (records: react_native_nfc_manager.NdefRecord[]) => Promise<void>;
178
- readonly writeTextNdef: (text: string) => Promise<void>;
179
- readonly writeUriNdef: (uri: string) => Promise<void>;
215
+ readonly Builder: typeof Builder;
216
+ readonly getStatus: typeof getStatus;
217
+ readonly readMessage: typeof readMessage;
218
+ readonly readFull: typeof readFull;
219
+ readonly write: typeof write;
220
+ readonly writeText: typeof writeText;
221
+ readonly writeUri: typeof writeUri;
222
+ readonly writeJson: typeof writeJson;
223
+ readonly writeMime: typeof writeMime;
224
+ readonly writeExternal: typeof writeExternal;
225
+ readonly makeReadOnly: typeof makeReadOnly;
226
+ };
227
+ readonly tag: {
228
+ readonly getTag: typeof getTag;
180
229
  };
181
230
  };
182
231
 
@@ -203,4 +252,4 @@ declare function useNfcTechnology(): {
203
252
  runWithTech: (tech: NfcTech | NfcTech[], fn: () => Promise<void>) => Promise<void>;
204
253
  };
205
254
 
206
- export { type NfcMode, NfcProvider, type NfcState, nfc, index$2 as nfcA, index as nfcNdef, nfcService, index$1 as nfcV, useNfc, useNfcContext, useNfcReader, useNfcState, useNfcTechnology };
255
+ export { type BuildRecordInit, type NdefBuilder, type NdefMessageResult, type NfcMode, NfcProvider, type NfcState, type SystemInfo, nfc, nfcNdefTag, nfcService, nfcTag, nfcVTag, useNfc, useNfcContext, useNfcReader, useNfcState, useNfcTechnology };